package com.soft.javase.day02.practice.game;

import java.util.Random;

/**
 * @author yzh
 * @desc TODO
 * @date 2025/4/16
 */
// 英雄类
class Hero {
    private String name;
    private int level;
    private int blood;
    private int power;
    private int defence;
    private String kind;
    private Equip[] equips;
    private int equipCount;

    public Hero(String name, int level, int blood, int power, int defence, String kind) {
        this.name = name;
        this.level = level;
        this.blood = blood;
        this.power = power;
        this.defence = defence;
        this.kind = kind;
        this.equips = new Equip[3];
        this.equipCount = 0;
    }

    // 攻击怪兽方法
    public void attack(Monster m) {
        Random rand = new Random();
        int damage = this.power;

        // 计算暴击 (30%几率)
        if (rand.nextInt(100) < 30) {
            int buff = rand.nextInt(10) + 5; // 暴击加成5-14
            damage += buff;
            System.out.println(name + " 打出暴击！额外造成 " + buff + " 点伤害！");
        }

        // 计算装备加成
        for (int i = 0; i < equipCount; i++) {
            damage += equips[i].getPower();
        }

        // 计算实际伤害
        int actualDamage = damage - m.getDefence();
        if (actualDamage <= 0) {
            System.out.println(name + " 的攻击未能破防！");
            return;
        }

        m.setBlood(m.getBlood() - actualDamage);
        System.out.println(name + " 对 " + m.getName() + " 造成了 " + actualDamage + " 点伤害！");
    }

    // 添加装备
    public boolean addEquip(Equip e) {
        if (equipCount >= 3) {
            System.out.println("装备已满，无法添加更多装备！");
            return false;
        }
        equips[equipCount] = e;
        equipCount++;
        // 装备属性加成
        this.power += e.getPower();
        this.defence += e.getDefence();
        return true;
    }

    // 判断是否死亡
    public boolean isDead() {
        return blood <= 0;
    }

    // 显示角色信息
    public void show() {
        System.out.println("英雄信息:");
        System.out.println("名称: " + name);
        System.out.println("等级: " + level);
        System.out.println("血量: " + blood);
        System.out.println("攻击力: " + power);
        System.out.println("防御力: " + defence);
        System.out.println("种族: " + kind);
        System.out.println("装备数量: " + equipCount);
        for (int i = 0; i < equipCount; i++) {
            equips[i].show();
        }
    }

    public String getName() { return name; }
    public int getLevel() { return level; }
    public int getBlood() { return blood; }
    public void setBlood(int blood) { this.blood = blood; }
    public int getPower() { return power; }
    public int getDefence() { return defence; }
    public String getKind() { return kind; }
}
